package util;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class ConexionJDBC {

    private Connection connection = null;
    public static final String CONNECTION_URL = "jdbc:sqlite:inventory";
    public static final String DRIVER_CLASSNAME = "org.sqlite.JDBC";

    public ConexionJDBC() {
        connection_SQL();
    }

    public void connection_SQL() {
        try {
            Class.forName(DRIVER_CLASSNAME);
            connection = DriverManager.getConnection(CONNECTION_URL);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(new JFrame(), "No se ha podido conectar a la base de datos.", "Error",
                    JOptionPane.ERROR_MESSAGE);
        }
    }

    public void close() {
        if (connection != null)
            try {
                connection.close();
            } catch (Exception e) {
            }
    }

    public Connection getConnection() {
        return connection;
    }

    public static void main(String [] arg) {
        ConexionJDBC conexion = new ConexionJDBC();

    }

	public void setAutoCommit(boolean b) {
		try {
			connection.setAutoCommit(b);
		} catch (SQLException e) {
			e.printStackTrace();
		}		
	}
}